var t = getApp(), a = void 0;

Page({
    data: {
        tags: [ "待配送", "配送中", "历史订单" ],
        tagFlag: 0,
        pageSize: 10,
        currentPage: 1,
        list: [],
        total: 0
    },
    onLoad: function(t) {
        a = this, this.getList(0), this.getTakeMode();
    },
    getTakeMode: function() {
        t.com.post("wx/config/takemode", {}, function(t) {
            0 == t.errno && a.setData({
                takemode: t.data.mode_type
            });
        });
    },
    updatePosition: function() {
        wx.showModal({
            title: "提示",
            content: "您的位置会根据接单地址的改变而改变，确定要手动刷新位置？",
            success: function(a) {
                a.confirm && wx.getLocation({
                    type: "gcj02",
                    success: function(a) {
                        wx.showLoading({
                            title: "更新中",
                            mask: !0
                        }), t.com.post("wx/user/updateLocation", {
                            latitude: a.latitude,
                            longitude: a.longitude
                        }, function(t) {
                            wx.hideLoading(), 0 === t.errno && wx.showToast({
                                title: t.errmsg
                            });
                        });
                    }
                });
            }
        });
    },
    changeTag: function(t) {
        a.setData({
            tagFlag: t.currentTarget.dataset.index
        }), a.getList(0);
    },
    getList: function(e) {
        0 == e ? this.data.currentPage = 1 : this.data.currentPage += 1, wx.showLoading({
            title: "加载中"
        }), t.com.post("wx/order/takelist", {
            pageSize: this.data.pageSize,
            currentPage: this.data.currentPage,
            tagFlag: this.data.tagFlag
        }, function(t) {
            wx.stopPullDownRefresh(), wx.hideLoading();
            for (var e in t.data.data) "nearby" != t.data.data[e].start_address && (t.data.data[e].start_address = JSON.parse(t.data.data[e].start_address)), 
            t.data.data[e].end_address = JSON.parse(t.data.data[e].end_address), t.data.data[e].filterDistance = t.data.data[e].distance > 999 ? (t.data.data[e].distance / 1e3).toFixed(1) + "公里" : t.data.data[e].distance + "米";
            0 === t.errno && a.setData({
                list: t.data.data,
                total: t.data.count
            });
        });
    },
    onPullDownRefresh: function() {
        this.getList(0);
    },
    onReachBottom: function() {
        this.data.list.length < this.data.total && this.getList(1);
    },
    receive: function(e) {
        var o = e.currentTarget.dataset.order_id;
        wx.showModal({
            title: "提示",
            content: "请确认接单",
            cancelText: "点错手误",
            success: function(e) {
                e.confirm && (wx.showLoading({
                    title: "加载中"
                }), t.com.post("wx/order/receive", {
                    order_id: o
                }, function(t) {
                    wx.hideLoading(), 0 === t.errno && (wx.showToast({
                        title: t.errmsg
                    }), a.getList(0));
                }));
            }
        });
    },
    confirmSend: function(e) {
        var o = e.currentTarget.dataset.order_id;
        wx.showModal({
            title: "提示",
            content: "请确认是否到达制定地点，若用户检举，将会受到处罚",
            cancelText: "点错手误",
            success: function(e) {
                e.confirm && (wx.showLoading({
                    title: "加载中"
                }), t.com.post("wx/order/confirmSend", {
                    order_id: o
                }, function(t) {
                    wx.hideLoading(), 0 === t.errno && (wx.showToast({
                        title: t.errmsg
                    }), a.getList(0));
                }));
            }
        });
    },
    confirmRun: function(e) {
        var o = e.currentTarget.dataset.order_id;
        wx.showModal({
            title: "提示",
            content: "请尽量让用户确认完成，避免不必要的纠纷",
            cancelText: "点错手误",
            confirmText: "任要确认",
            success: function(e) {
                e.confirm && (wx.showLoading({
                    title: "加载中"
                }), t.com.post("wx/orderConfirm/run", {
                    order_id: o
                }, function(t) {
                    wx.hideLoading(), 0 === t.errno && (wx.showToast({
                        title: t.errmsg
                    }), a.getList(0));
                }));
            }
        });
    },
    cancelOrder: function(t) {}
});